package com.herui.iot.ui.dialog;

import android.app.Dialog;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CalendarView;

import com.herui.sdyu_lib.base.BaseActivity;
import com.herui.sport_care.R;
import com.herui.sport_care.utils.ViewTools;
import com.protontek.healthy.sdkcore.sphygmomanometer.api.BPDataBean;

import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by amanda.shan on 2022/12/14.
 */
public class DateChoseDialog {

    static String TAG = "DateChoseDialog";

    private Dialog dialog;

    @BindView(R.id.calendarView)
    CalendarView calendarView;

    private DialogLis dialogLis;

    public DateChoseDialog(BaseActivity context, DialogLis dialogLis) {

        this.dialogLis = dialogLis;

        View layout = (View) context
                .getLayoutInflater().inflate(R.layout.dialog_chose_date,
                        null);
        ButterKnife.bind(this, layout);
        dialog = new Dialog(context, R.style.MyDialogStyleBottom);
        dialog.setContentView(layout);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();
        Window dialogWindow = dialog.getWindow();
        dialogWindow.setLayout((int) ViewTools.fromDpToPx(350), (int) ViewTools.fromDpToPx(400));
        dialogWindow.setGravity(Gravity.CENTER);
    }

    @OnClick({R.id.btn_ok})
    public void onViewClick(View view) {
        switch (view.getId()) {
            case R.id.btn_ok:
                long date = calendarView.getDate();
                dialogLis.onOk(date);
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                Log.i(TAG, "onViewClick: 选择的日期:"+format.format(new Date(date)));
                dialog.dismiss();
                break;
            default:
                break;
        }

    }

    public interface DialogLis {
        void onOk(long date);
    }
}
